#ifndef _USER_LED_WS2812_DRIVE_H_
#define _USER_LED_WS2812_DRIVE_H_

#include "platform_api.h"
#include "profile.h"


enum app_state
{
    APP_ADV,
    APP_CONN,
    APP_POWER_LOW,
    APP_IDLE
};
// blink styles
typedef enum
{
    BLINK_ON,       // always on
    BLINK_OFF,      // always off
    BLINK_FAST,     // blink fast
    BLINK_SLOW,     // blink slow
} blink_style_t;

#define WS2812_SPI_DRV_PORT      AHB_SSP0


#define SPI_DMA_TX_CHANNEL   (0)//DMA channel 0


#define WS2812B_DO        GIO_GPIO_28
//GIO_GPIO_11
//#define WS2812B_DO        GIO_GPIO_11
#define log_printf    platform_printf


#define RGB_LED_MAX_NUM  			(1u)

#define SPI_SPEED_4M			6
#define SPI_SPEED_8M			2

#define LED_WS2812_SPI_SPEED	SPI_SPEED_4M

#if (LED_WS2812_SPI_SPEED == SPI_SPEED_4M)

#define LED_WS2812_HIGH	0X0E
#define LED_WS2812_LOW	0X08

#define DMA_TRANS_SIZE		((RGB_LED_MAX_NUM) * (12))

#else

#define LED_WS2812_HIGH	0XFC
#define LED_WS2812_LOW	0XC0

#define DMA_TRANS_SIZE		((RGB_LED_MAX_NUM) * (24))

#endif

#define TRANS_DATA_NUM		((DMA_TRANS_SIZE) >> (2))

#define SPI_TRANS_CTRL_VALUE    (*(uint32_t *)0x40160020)
#define SPI_SET_WRITE_CNT(c)    SPI_TRANS_CTRL_VALUE = ((SPI_TRANS_CTRL_VALUE & (~(0x1ff << 12))) | ((c - 1) << 12))

void show_app_state(enum app_state state);
void LED_Task_Init(void);
void bsp_led_on_off(uint8_t on_off);
uint8_t LED_Init(void);
void LED_uninit(void);
void restore_show_app_state(void);
#endif